package com.sang.web;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.sang.VO.UserVO;
import com.sang.busTest.SpringBootBusTest;
import com.sang.service.Userservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping
public class UserController {

    @Autowired
    Userservice userservice;
    @Autowired
    SpringBootBusTest springBootBusTest;

    @GetMapping("/user/{id}")
    @HystrixCommand(fallbackMethod = "queryByIdFallBack")
    public UserVO findById(@PathVariable("id") String username){
        System.out.println("SpringBus测试端口"+springBootBusTest.getPort());
        return userservice.findById(username);
    }

    // 降级方法
    public UserVO queryByIdFallBack(String username) {
        UserVO user = new UserVO();
        user.setName("暂停服务");
        return user;
    }

}
